Spot-On
spot-on-gui-server.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef _spoton_gui_server_h_
29 #define _spoton_gui_server_h_
30 
31 #include <QFileSystemWatcher>
32 #include <QPointer>
33 #include <QQueue>
34 #include <QSslSocket>
35 #include <QTcpServer>
36 #include <QTimer>
37 
38 class spoton_gui_server_tcp_server: public QTcpServer
39 {
40  Q_OBJECT
41 
42  public:
43  spoton_gui_server_tcp_server(QObject *parent):QTcpServer(parent)
44  {
45  }
46 
48  {
49  while(!m_queue.isEmpty())
50  {
51  QPointer<QSslSocket> socket = m_queue.dequeue();
52 
53  if(socket)
54  socket->deleteLater();
55  }
56  }
57 
58  QSslSocket *nextPendingConnection(void)
59  {
60  if(m_queue.isEmpty())
61  return 0;
62  else
63  return m_queue.dequeue();
64  }
65 
66  void incomingConnection(qintptr socketDescriptor);
67 
68  private:
69  QQueue<QPointer<QSslSocket> > m_queue;
70 
71  signals:
72  void modeChanged(QSslSocket::SslMode mode);
73  void newConnection(void);
74 };
75 
77 {
78  Q_OBJECT
79 
80  public:
81  spoton_gui_server(QObject *parent);
83 
84  private:
85  QFileSystemWatcher m_fileSystemWatcher;
86  QHash<qintptr, QByteArray> m_guiSocketData;
87  QHash<qintptr, bool> m_guiIsAuthenticated;
88  QTimer m_generalTimer;
89  void sendMessageToUIs(const QByteArray &message);
90 
91  private slots:
92  void slotAuthenticationRequested(const QString &peerInformation);
93  void slotBytesReceived(const qint64 size);
94  void slotBytesSent(const qint64 size);
95  void slotClientConnected(void);
96  void slotClientDisconnected(void);
97  void slotEncrypted(void);
98  void slotFileChanged(const QString &path);
99  void slotForwardSecrecyRequest(const QByteArrayList &list);
100  void slotForwardSecrecyResponse(const QByteArrayList &list);
101  void slotModeChanged(QSslSocket::SslMode mode);
102  void slotNewEMailArrived(void);
103  void slotNotification(const QString &text);
104  void slotReadyRead(void);
105  void slotReceivedBuzzMessage(const QByteArrayList &list,
106  const QByteArrayList &keys);
107  void slotReceivedChatMessage(const QByteArray &message);
108  void slotSMPMessage(const QByteArrayList &list);
109  void slotStatusMessageReceived(const QByteArray &publicKeyHash,
110  const QString &status);
111  void slotTimeout(void);
112 
113  signals:
114  void buzzMagnetReceivedFromUI(const qint64 oid, const QByteArray &magnet);
115  void buzzReceivedFromUI(const QByteArray &channel,
116  const QByteArray &channelType,
117  const QByteArray &name,
118  const QByteArray &id,
119  const QByteArray &message,
120  const QByteArray &sendMethod,
121  const QString &messageType,
122  const QByteArray &hashKey,
123  const QByteArray &hashType,
124  const QByteArray &dateTime);
125  void callParticipant(const QByteArray &keyType, const qint64 oid);
126  void callParticipantUsingForwardSecrecy(const QByteArray &keyType,
127  const qint64 oid);
128  void callParticipantUsingGemini(const QByteArray &keyType, const qint64 oid);
129  void detachNeighbors(const qint64 oid);
130  void disconnectNeighbors(const qint64 oid);
131  void echoKeyShare(const QByteArrayList &list);
132  void forwardSecrecyInformationReceivedFromUI(const QByteArrayList &list);
133  void forwardSecrecyResponseReceivedFromUI(const QByteArrayList &list);
134  void initiateSSLTLSSession(const bool client, const qint64 oid);
135  void messageReceivedFromUI(const qint64 oid,
136  const QByteArray &name,
137  const QByteArray &message,
138  const QByteArray &sequenceNumber,
139  const QByteArray &utcDate,
140  const QString &keyType);
141  void poptasticPop(void);
142  void populateStarBeamKeys(void);
143  void publicKeyReceivedFromUI(const qint64 oid,
144  const QByteArray &keyType,
145  const QByteArray &name,
146  const QByteArray &publicKey,
147  const QByteArray &signature,
148  const QByteArray &sPublicKey,
149  const QByteArray &sSignature,
150  const QString &messageType);
151  void publicizeAllListenersPlaintext(void);
152  void publicizeListenerPlaintext(const qint64 oid);
153  void purgeEphemeralKeyPair(const QByteArray &publicKeyHash);
154  void purgeEphemeralKeys(void);
155  void retrieveMail(void);
156  void shareLink(const QByteArray &link);
157  void smpMessageReceivedFromUI(const QByteArrayList &list);
158 };
159 
160 #endif
spoton_gui_server_tcp_server
Definition: spot-on-gui-server.h:38
spoton_gui_server
Definition: spot-on-gui-server.h:76